package luanvan.app.foodnote;

import com.actionbarsherlock.app.SherlockPreferenceActivity;

import luanvan.app.foodnote.library.SettingManager;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;

public class ShowSettingActivity extends SherlockPreferenceActivity implements OnSharedPreferenceChangeListener{

	SettingManager settingManager;
	
	@SuppressWarnings("deprecation")
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        addPreferencesFromResource(R.xml.preferences);
        
        getSupportActionBar().setIcon(R.drawable.setting_tools);
        getSupportActionBar().show();
	    settingManager = new SettingManager(getApplicationContext());
	    
	 }
	@SuppressWarnings("deprecation")
	@Override
	protected void onResume() {
	    super.onResume();
	    // Set up a listener whenever a key changes
	    getPreferenceScreen().getSharedPreferences()
	            .registerOnSharedPreferenceChangeListener(this);
	}
	@SuppressWarnings("deprecation")
	@Override
	protected void onPause() {
	    super.onPause();
	    // Unregister the listener whenever a key changes
	    getPreferenceScreen().getSharedPreferences()
	            .unregisterOnSharedPreferenceChangeListener(this);
	}
	@Override
	public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
			String key) {

		if(key.equals("showlist")){
			//SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
			String value = sharedPreferences.getString("showlist", null);
			settingManager.createSetting(value);
			settingManager.checkChanged(value);
			Intent i = getIntent();
			setResult(101, i);
			finish();
		}

	}
	 
}
